package com.link.base.base.quote.controller;

import com.link.base.base.quote.service.QuoteItemService;
import com.link.base.base.quote.model.QuoteItem;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.ServiceException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author unknown
 * @date unknown
 * @comments 报价单明细
 */
@Controller
@RequestMapping("/link/QuoteItem")
public class QuoteItemController extends BasicController<QuoteItem> {

    @Resource
    private QuoteItemService quoteItemService;

    @Override
    public BasicService<QuoteItem> getBasicService() throws Exception {
        if (quoteItemService != null) {
            return quoteItemService;
        }
        throw new ServiceException("PUBLIC-005");
    }

    @Override
    public void beforQueryAllOrExample(QuoteItem entity, HttpServletRequest request) throws Exception {
        super.beforQueryAllOrExample(entity, request);
        if (null == entity.getQuoteId()) {
            entity.setQuoteId(0L);
        }
    }

    /*//查询报价单产品列表
    @RequestMapping(value="/queryQuoteItemSelect", produces="application/json")
    @ResponseBody
    public Map<String,Object> queryQuoteItemSelect(QueryParams qps,HttpSession session ,HttpServletRequest request,HttpServletResponse response) {
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            //存在父子级联，所以强制父Id不能为空
            qps.invokePreFilterAndSorter();
            List<Filter> filterList = qps.getFilterByProperty("quoteId");
            if(filterList == null || filterList.size() == 0){
                qps.addFilter(new Filter("quoteId","noMatchId"));
            }
            List<QuoteItem> list = quoteItemService.queryQuoteItemSelect(qps);
            result.put("success", true);
            result.put("rows",list);
        }catch(Exception e){
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    //删除报价单产品列表
    @RequestMapping(value="/delQuoteProdById", method = RequestMethod.POST, produces="application/json")
    @ResponseBody
    public Map<String,Object> delQuoteProdById(String id,HttpSession session ,HttpServletRequest request,HttpServletResponse response) {
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            QuoteItem item = new QuoteItem();
            if(id == null || "".equals(id)){
                throw new BasicControllerException("Id不能为空！");
            }
            item.setId(id);
            quoteItemService.delQuoteItemById(item);
            result.put("success", true);
        }catch(Exception e){
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    */
}
